<?php
/**
 * Created by ModelCreater.
 * Date: 2023-09-22
 * Time: 17:30:00
 */

namespace model;

use Carbon\Carbon;
use lib\common\CommonModel;
use think\model\concern\SoftDelete;

class AdminPermissionMenuModel extends CommonModel
{


    protected $table = 'admin_permission_menu';

    protected $autoWriteTimestamp = 'datetime';
    protected $createTime = 'create_time';
    protected $updateTime = false;

    protected $schema = [
        'permission_id' => 'int',
        'menu_id'       => 'int',
        'create_time'   => 'datetime',
    ];

    public function saveBatch ($permissionId, array $menuIds): void {
        $menuIds = array_values($menuIds);
        $now = Carbon::now()->toDateTimeString();
        $saveData = array_map(function ($menuId) use ($now, $permissionId) {
            return [
                'permission_id' => $permissionId,
                'menu_id'       => $menuId,
                'create_time'   => $now
            ];
        }, $menuIds);
        if (!empty($saveData)) $this->insertAll($saveData);
    }
}
